package com.project.class8_24.factory.dao.impl;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

public class DaoFactory {
    private static Properties pro = new Properties();
    static{
        try {
            pro.load(new FileReader("daoFactory.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 根据接口名，得到实现类对象
     * @param interfaceName 接口名称
     * @return 实现类对象
     */
    public static Object getDao(String interfaceName){
        String value = pro.getProperty(interfaceName);
        if(value == null){
            return null;
        }
        try {
            //加载类，得到类模版
           Class c =  Class.forName(value);
           return c.getConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
